package br.cell.view;

import static java.awt.Color.BLUE;
import static java.awt.Color.RED;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class EvolvingCells {

	public static void main(String[] args) {
		MyFrame myFrame = new MyFrame(new MyPanel());
		myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		myFrame.setLocationRelativeTo(null);
		myFrame.setVisible(true);

		myFrame.repaint();
	}

	private static class MyFrame extends JFrame {

		private static final long serialVersionUID = 8849943210402372578L;

		private MyPanel panel;

		public MyFrame(MyPanel panel) {
			super("Evolving Cells");
			this.setSize(600, 600);
			this.panel = panel;
			this.add(panel);
		}

		@Override
		public void repaint() {
			this.panel.repaint();
			//			super.repaint();
		}
	}

	private static class MyPanel extends JPanel {

		private static final long serialVersionUID = -4100300484935938091L;

		public MyPanel() {
			super(true);
		}

		@Override
		public void paintComponent(Graphics g) {
			Point point = new Point(100, 100);
			Rectangle rectangle = new Rectangle(point);
			rectangle.width = 5;
			rectangle.height = 5;

			Graphics2D g2d = (Graphics2D) g.create();
			g2d.setColor(BLUE);
			g2d.fill(rectangle);
		}

		public void addRect() {
			Point point = new Point(150, 150);
			Rectangle rectangle = new Rectangle(point);
			rectangle.width = 5;
			rectangle.height = 5;

			Graphics2D g2d = (Graphics2D) getGraphics().create();
			g2d.setColor(RED);
			g2d.fill(rectangle);
		}
	}
}